// Author	: damphat@gmail.com
// Created	: 01/12/2008

#pragma once
#include "vn/NetCommon.h"
#include "vn/IPHostEntry.h"

NET_BEGIN

class Dns {
private:
	Dns();
public:
	static String GetHostName() {
		Char buf[256];
		SocketStartup();
		int ret = gethostname(buf, 256);
		CHECK_WINSOCK(ret != SOCKET_ERROR);
		return buf;
	}

	// if hostname is empty, return v4 addresses
	static IPHostEntry GetHostEntry(const String &hostname) {
		SocketStartup();
		StringA ansi = hostname;
		hostent* ent = gethostbyname(ansi.C_STR());
		CHECK_WINSOCK(ent != 0);
		return ent;
	}

	static IPHostEntry GetHostEntry(const IPAddress &addr) {
		SocketStartup();
		hostent* ent = gethostbyaddr(
			addr.GetData(),
			addr.GetLength(),
			addr.GetAddressFamily());

		CHECK_WINSOCK(ent != 0);
		return ent;
	}
};

NET_END
